const {ccclass, property} = cc._decorator;

@ccclass
export default class QBar extends cc.Component {
    private text:cc.Label;    
    private bar:cc.ProgressBar;
    private current:number;
    private max:number;    
    onLoad(){
        this.text = this.node.getChildByName("text").getComponent(cc.Label);
        this.bar = this.getComponent(cc.ProgressBar);        
    }

    init(current:number,max:number){
        this.current = current;
        this.max = max;
        this.updateUI();
    }

    change(value:number){
        this.current+=value;
        this.updateUI();
    }

    hideText(){
        this.text.enabled = false;
    }
    showText(){
        this.text.enabled = true;
    }

    hide(){
        this.node.active = false;
    }
    show(){
        this.node.active = true;
        this.updateUI();
    }

    updateUI(){
        this.text.string = this.current+"/"+this.max;                
        this.bar.progress = this.current/this.max;
    }
}
